<template>
  <div class="app">
    <!-- 顶部标题区 -->
    <header class="app-header">
      <h1 class="app-title">Vue3 主应用平台</h1>
      <p class="app-desc">集成子应用的微前端示例</p>
    </header>

    <!-- 导航栏 -->
    <nav class="nav">
      <router-link
          to="/"
          class="nav-link"
          active-class="nav-link--active"
          @mouseenter="isHover = true"
          @mouseleave="isHover = false"
      >
        <span class="link-text">主页面 Home</span>
      </router-link>
      <router-link
          to="/about"
          class="nav-link"
          active-class="nav-link--active"
      >
        <span class="link-text">主页面 About</span>
      </router-link>
      <router-link
          to="/sub-app"
          class="nav-link nav-link--highlight"
          active-class="nav-link--active"
      >
        <span class="link-text">进入vue3子应用</span>
      </router-link>
    </nav>

    <!-- 主内容区（带加载动画容器） -->
    <div class="main-container">
      <transition name="page-fade" mode="out-in">
        <router-view class="main-content" key="$route.fullPath"/>
      </transition>
    </div>

    <!-- 页脚 -->
    <footer class="app-footer">
      <p>© 2025 Vue3 微前端示例 | 设计优化版</p>
    </footer>
  </div>
</template>

<script setup>
import {ref} from 'vue';

const isHover = ref(false); // 用于hover状态精细化控制（可选扩展）
</script>

<style scoped>

/* 基础样式重置与全局配置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', 'system-ui', -apple-system, sans-serif;
}

body {
  background-color: #f8fafc;
  color: #334155;
  line-height: 1.5;
  padding: 0;
  margin: 0;
}

/* 应用容器 */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* 头部标题区 */
.app-header {
  margin-bottom: 32px;
  text-align: center;
  padding-bottom: 16px;
  border-bottom: 1px solid #e2e8f0;
}

.app-title {
  font-size: 28px;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.app-desc {
  font-size: 16px;
  color: #64748b;
  font-weight: 400;
}

/* 导航栏样式 */
.nav {
  display: flex;
  align-items: center;
  background-color: #ffffff;
  border-radius: 12px;
  padding: 0 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  margin-bottom: 32px;
  height: 64px;
  transition: box-shadow 0.3s ease;
}

.nav:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

/* 导航链接基础样式 */
.nav-link {
  display: flex;
  align-items: center;
  color: #64748b;
  text-decoration: none;
  padding: 0 16px;
  height: 100%;
  font-size: 15px;
  font-weight: 500;
  transition: all 0.25s ease;
  position: relative;
  gap: 8px; /* 图标与文字间距 */
}

/* 导航链接hover效果 */
.nav-link:hover {
  color: #2563eb;
  background-color: rgba(37, 99, 235, 0.04);
}

/* 导航链接激活状态 */
.nav-link--active {
  color: #2563eb;
  font-weight: 600;
}

/* 激活状态下划线（动画效果） */
.nav-link--active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background-color: #2563eb;
  border-radius: 3px 3px 0 0;
  animation: underlineFadeIn 0.3s ease forwards;
}

/* 子应用特殊高亮按钮 */
.nav-link--highlight {
  color: #2563eb;
  margin-left: auto; /* 右对齐 */
}

.nav-link--highlight:hover {
  background-color: rgba(37, 99, 235, 0.1);
}

/* 图标样式统一 */
.icon-home, .icon-about, .icon-subapp {
  font-size: 16px;
}

/* 主内容区域容器 */
.main-container {
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  transition: all 0.3s ease;
}

.main-container:hover {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

/* 主内容区 */
.main-content {
  padding: 32px;
  min-height: 400px;
}

/* 子应用容器（如果子应用需要特殊样式） */
.subapp {
  background-color: #ffffff;
  padding: 24px;
  border-radius: 8px;
  min-height: 300px;
  border-top: 4px solid #2563eb;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
  margin-top: 16px;
}

/* 页面切换过渡动画 */
.page-fade-enter-from,
.page-fade-leave-to {
  opacity: 0;
  transform: translateY(10px);
}

.page-fade-enter-active,
.page-fade-leave-active {
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* 下划线动画 */
@keyframes underlineFadeIn {
  from {
    width: 0;
    left: 50%;
  }
  to {
    width: 100%;
    left: 0;
  }
}

/* 页脚样式 */
.app-footer {
  margin-top: 40px;
  text-align: center;
  padding-top: 16px;
  border-top: 1px solid #e2e8f0;
  color: #64748b;
  font-size: 14px;
}

/* 响应式适配（移动端优化） */
@media (max-width: 768px) {
  .app {
    padding: 16px;
  }

  .app-title {
    font-size: 24px;
  }

  .nav {
    padding: 0 16px;
    height: auto;
    flex-wrap: wrap;
  }

  .nav-link {
    padding: 12px 16px;
    width: 100%;
    justify-content: center;
  }

  .nav-link--highlight {
    margin-left: 0;
    order: 3; /* 子应用链接放最后 */
  }

  .main-content {
    padding: 20px;
  }

  .link-text {
    font-size: 14px;
  }
}
</style>
